package com.example.message.adapter

import android.view.View
import com.alibaba.android.arouter.launcher.ARouter
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.BaseViewHolder
import com.example.module.R
import com.gsafety.libraryktx.bean.WarnData
import com.gsafety.libraryktx.config.Constant
import com.gsafety.libraryktx.core.RouterConstants

/**消息列表适配器
 * @author : lj
 * @date : 2021/1/4 11:01
 */
class MessageAdapter(data: List<WarnData.RecordsBean>) : BaseQuickAdapter<WarnData.RecordsBean, BaseViewHolder>(R.layout.message_item_news, data) {
    override fun convert(helper: BaseViewHolder?, item: WarnData.RecordsBean?) {
        helper!!.itemView.setOnClickListener {
            ARouter.getInstance().build(RouterConstants.ALARM_DETAIL_ACTIVITY).withSerializable("records",item).navigation()
        }
        helper!!.getView<View>(R.id.ll_attend).setOnClickListener {
            onItemAttentionClickListener?.onItemAttendClick(helper.layoutPosition)
        }
        item?.let {
            helper.setText(R.id.tv_alarm_title, item.adtevtName)
            helper.setText(R.id.tv_alarm_time, item.pubTime)
            helper.setText(R.id.tv_alarm_addr, item.adtevtGeoaddr)
            helper.setText(R.id.number, item.unread.toString())
            when (it.adtevtLevel) {
                1 -> {
                    helper.setTextColor(
                        R.id.tv_alarm_level,
                        mContext.resources.getColor(R.color.common_color_first_level)
                    )
                    helper.setText(R.id.tv_alarm_level, "一级报警")
                }
                2 -> {
                    helper.setTextColor(
                        R.id.tv_alarm_level,
                        mContext.resources.getColor(R.color.common_color_second_level)
                    )
                    helper.setText(R.id.tv_alarm_level, "二级报警")
                }
                3 -> {
                    helper.setTextColor(
                        R.id.tv_alarm_level,
                        mContext.resources.getColor(R.color.common_color_third_level)
                    )
                    helper.setText(R.id.tv_alarm_level, "三级报警")
                }
                4 -> {
                    helper.setTextColor(
                        R.id.tv_alarm_level,
                        mContext.resources.getColor(R.color.common_color_fourth_level)
                    )
                    helper.setText(R.id.tv_alarm_level, "四级报警")
                }
            }
            when (it.attended) {
                true -> {
                    helper.setImageResource(R.id.iv_attend, R.mipmap.common_icon_has_saved1)
                    helper.setText(R.id.tv_attend,"取消关注")
                }
                false -> {
                    helper.setImageResource(R.id.iv_attend, R.mipmap.common_icon_save1)
                    helper.setText(R.id.tv_attend,"关注")
                }
            }

            when (it.adtevtStatus) {
                Constant.NO_DEAL_CODE.toInt() -> helper.setImageResource(R.id.iv_alarm_status, R.mipmap.common_tag_no_deal)
                Constant.IN_DEAL_CODE.toInt() -> helper.setImageResource(R.id.iv_alarm_status, R.mipmap.common_tag_in_deal)
                Constant.HAS_DEAL_CODE.toInt() -> helper.setImageResource(R.id.iv_alarm_status, R.mipmap.common_tag_has_finish)
                else -> helper.setImageResource(R.id.iv_alarm_status, R.mipmap.common_tag_has_finish)
            }

            if(it.specialsys == Constant.GAS_PROJECT){
                helper.setImageResource(R.id.iv_alarm_type, R.mipmap.common_icon_gas)
            }else if(it.specialsys == Constant.HEAT_PROJECT){
                helper.setImageResource(R.id.iv_alarm_type, R.mipmap.common_icon_heat)
            }else if(it.specialsys == Constant.DRAIN_PROJECT){
                helper.setImageResource(R.id.iv_alarm_type, R.mipmap.common_icon_drain)
            }else if(it.specialsys == Constant.WATER_PROJECT){
                helper.setImageResource(R.id.iv_alarm_type, R.mipmap.common_icon_water)
            } else if(it.specialsys == Constant.BRIDGE_PROJECT){
                helper.setImageResource(R.id.iv_alarm_type, R.mipmap.common_icon_bridge)
            }else{

            }
        }
    }

    var onItemAttentionClickListener:OnItemAttentionClickListener? = null

    interface OnItemAttentionClickListener{
        fun onItemAttendClick(pos:Int)
    }
}